<?php
require_once 'smarty_lib/Smarty.class.php';
require_once 'lib/DBClass.php';
require_once 'lib/Account.php';

$smarty = new Smarty();
$acc = new Account();

$smarty->template_dir = 'template/';
$smarty->compile_dir = 'template_c/';

if(isset($_POST['submit'])){
	
	if($_POST['email']=='' or $_POST['password']=='')
		$smarty->assign('error','Masukan email dan Password Anda');
	else{
		
		$acc->set_user($_POST['email']);
		$acc->set_password($_POST['password']);
		
		if($acc->do_login()){
			header('location: dashboard.php');
		}else{
			$smarty->assign('error','Password atau Username tidak sesuai,');
		}			
	}		
}else if(isset($_GET['a']) && $_GET['a']=='logout'){
	$acc->do_logout();
	$smarty->assign('success','Log Out Sukses');
}else if($acc->validate_cookie()){
	header('location: dashboard.php');
}

$smarty->display('login.html');

?>